package a66weding.com.jiehuntong.activity.order.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.adapter.MyBaseAdapter;
import a66weding.com.jiehuntong.beans.MyOrderBean;

/**
 * Created by admin on 2016/9/1.
 */
public class RefundAdapter extends MyBaseAdapter {


    public RefundAdapter(Context context, List data) {
        super(context, data);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {

        MyOrderBean.DataBean.MyOrderDetailBean.OrderOperateInfosBean orderOperateInfosBean = (MyOrderBean.DataBean.MyOrderDetailBean.OrderOperateInfosBean) data.get(position);
        ViewHolder holder;
        if (convertView==null){
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.item_refund,null);
            holder.item_refund_line1 = (View) convertView.findViewById(R.id.item_refund_line1);
            holder.item_refund_line2 = (View) convertView.findViewById(R.id.item_refund_line2);
            holder.item_refund_icon = (ImageView) convertView.findViewById(R.id.item_refund_icon);
            holder.item_refund_tv_time = (TextView) convertView.findViewById(R.id.item_refund_tv_time);
            holder.item_refund_tv_content = (TextView) convertView.findViewById(R.id.item_refund_tv_content);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();

        }


        if (!(orderOperateInfosBean.getRemark().isEmpty())){
            holder.item_refund_tv_content.setText(orderOperateInfosBean.getRemark());
        } else {
            holder.item_refund_tv_content.setText("——");
        }
        String datetime = orderOperateInfosBean.getDatetime();
        if(datetime.contains("T")) {
            String[] times = datetime.split("T");
            holder.item_refund_tv_time.setText(times[0]+" "+times[times.length-1]);
        }

        if (position==0){
            holder.item_refund_line1.setVisibility(View.INVISIBLE);
            holder.item_refund_icon.setImageResource(R.mipmap.reddian);
            holder.item_refund_line2.setVisibility(View.VISIBLE);
        }else if(position==data.size()-1){
            holder.item_refund_line2.setVisibility(View.INVISIBLE);
            holder.item_refund_icon.setImageResource(R.mipmap.reddian);
            holder.item_refund_line1.setVisibility(View.VISIBLE);
        }else{
                holder.item_refund_line1.setVisibility(View.VISIBLE);
                holder.item_refund_icon.setImageResource(R.mipmap.reddian);
                holder.item_refund_line2.setVisibility(View.VISIBLE);
        }
        //判断如果等于集合的长度的时候就隐藏下一部分;

        return convertView;
    }

    public class ViewHolder{
        //上面的线;
        View item_refund_line1;
        //下面的线
        View item_refund_line2;
        //进度图标
        ImageView item_refund_icon;
        //进度状态
        TextView item_refund_tv_content;
        //时间
        TextView item_refund_tv_time;
    }
}
